package leader.action;

import java.util.ArrayList;
import java.util.List;

import leader.service.DirectPaperService;
import leader.service.DirectTeacherService;
import leader.service.DirectTreatiseService;
import leader.tool.JTableDefine;
import teacher.bean.Paper;
import teacher.bean.Teacher;
import teacher.bean.Treatise;
import tools.StringDate;

import com.opensymphony.xwork2.ActionContext;

public class DirectPaperPrintAction {
	private String datedown;
	private String dateup;
	private String treName;
	private int flag;
	public String getDatedown() {
		return datedown;
	}

	public void setDatedown(String datedown) {
		this.datedown = datedown;
	}

	public String getDateup() {
		return dateup;
	}

	public void setDateup(String dateup) {
		this.dateup = dateup;
	}

	public String getTreName() {
		return treName;
	}

	public void setTreName(String treName) {
		this.treName = treName;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public String execute() {
		Teacher lea=(Teacher) ActionContext.getContext().getSession().get("leader");
		DirectTeacherService DT = new DirectTeacherService();
		List<Paper> lists = new ArrayList<Paper>();
		DirectPaperService DP = new DirectPaperService();
//		lea.setDirection(0);
//		System.out.println(lea.getTeaId());
//		System.out.println(lea.getDirection());
//		System.out.println(DP.selectAllDirectPaper(lea).size());
		lists = DP.selectAllDirectPaper(lea);
		System.out.println(lists.size());
//		for(int i=0;i<lists.size();i++) {
//			System.out.println("========="+lists.get(i).getName());
//		}
		System.out.println("========="+flag);
		if(0 == flag) {
			lists = DP.selectAllDirectPaper(lea);
		}
		if(1 == flag) {
			StringDate date = new StringDate();
			lists = DP.selectDirectPaperByTime(date.StringToDate(datedown),date.StringToDate(dateup), lea);
		}
		if(2 == flag) {
			lists = DP.selectPaperLikeName(treName, lea);
		}
		if(3 == flag) {
			Paper pap = new Paper();
			pap.setState(0);
			lists = DP.selectDirectPaperByState(lea, pap);
		}
		String[][] columnNames = new String[lists.size()+1][7];		
		columnNames[0] = new String[]{"编号","名称","作者","通讯作者","期刊","发表日期","期刊类型"};
		for(int i=1;i<lists.size()+1;i++) {
			Paper paper = lists.get(i-1);
//			System.out.println(paper.getName());
			columnNames[i][0] = String.valueOf(i);
			columnNames[i][1] = paper.getName();
			System.out.println(paper.getName());
			columnNames[i][2] = paper.getFauthor();
			System.out.println(paper.getFauthor());
			System.out.println(paper.getTeaId());
			Teacher tea = new Teacher();
			tea.setTeaId(paper.getTeaId());			
			columnNames[i][3] = DT.selectTeacherById(tea).getName();
			System.out.println(DT.selectTeacherById(tea).getName());
			columnNames[i][4] = paper.getPbulication();
			System.out.println(paper.getPbulication());
			StringDate date = new StringDate();
			columnNames[i][5] = date.DateToString(paper.getDate());
			System.out.println(date.DateToString(paper.getDate()));
			columnNames[i][6] = "待定";
		}
		int[] px = new int[]{40,120,50,50,105,80,80};
		JTableDefine d = new JTableDefine();
		d.printTable(columnNames,px);
		System.out.println("============================");
		return "success";
	}
}
